var $;
layui.use(['layer', 'form', 'table', 'jquery', 'laydate'], function () {
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    $ = layui.jquery;
    var laydate = layui.laydate;
    laydate.render({
        elem: '#applyDate',
        type: 'date',
        trigger: 'click'
    });
    var result = 2;
    //通过
    $('#adopt').on('click', function () {
        getTable(2);
        result = 2;
        $('input[name=account]').val('');
        $('input[name=fullName]').val('');
        $('input[name=applyDate]').val('');
    });
    //未通过
    $('#fail').on('click', function () {
        getTable(3);
        result = 3;
        $('input[name=account]').val('');
        $('input[name=fullName]').val('');
        $('input[name=applyDate]').val('');
    });
    //加载表格
    getTable(2);

    function getTable(result) {
        $.ajax({
            url: '/record/getApplyRecord',
            type: 'post',
            dataType: 'json',
            data: {'result': result, 'position': 1},
            success: function (data) {
                tablereload(data.data);
            }
        });
    }

    var tableIns;

    function tablereload(data) {
        tableIns = table.render({
            elem: '#table',
            title: '已处理申请列表',
            data: data,
            toolbar: '#apply',
            page: {
                limit: 10,
                layout: ['count', 'prev', 'page', 'next', 'skip', 'refresh'],
                first: "首页",
                last: "尾页",
            },
            cols: [[
                {type: 'checkbox', with: 50, fixed: 'left'},
                {
                    field: '', title: '序号', align: 'center', templet: function (data) {
                        return data.LAY_INDEX;
                    }
                },
                {field: 'fullName', title: '用户姓名', align: 'center'},
                {field: 'account', title: '用户账号', align: 'center'},
                {field: 'roleName', title: '申请职位', align: 'center'},
                {field: 'phone', title: '电话', align: 'center'},
                {field: 'applyDate', title: '申请时间', align: 'center'},
                {field: 'email', title: '邮箱', align: 'center'},
                {
                    field: 'result', title: '申请状态', align: 'center', templet: function (data) {
                        if (data.result == 1) {
                            return "未审核";
                        } else if (data.result == 2) {
                            return "已通过";
                        } else {
                            return "已驳回";
                        }
                    }
                }
            ]]
        });
    }

    //搜索
    form.on('submit(search)', function (data) {
        $.ajax({
            url: '/record/getApplyRecord?position=1&result=' + result,
            type: 'post',
            dataType: 'json',
            data: data.field,
            success: function (data) {
                tablereload(data.data);
            }
        });
    });

});

//返回
function goBack() {
    //通过页面查找iframe
    parent.$('#recordLog').val($('#processed').text());
    parent.before();
    return false;
}